package com.example.project.service.impl;

import com.example.project.entity.TcdmSecureHazardAssessmentRules;
import com.example.project.dao.TcdmSecureHazardAssessmentRulesDao;
import com.example.project.service.TcdmSecureHazardAssessmentRulesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (TcdmSecureHazardAssessmentRules)表服务实现类
 *
 * @author makejava
 * @since 2024-02-23 15:18:23
 */
@Service("tcdmSecureHazardAssessmentRulesService")
public class TcdmSecureHazardAssessmentRulesServiceImpl implements TcdmSecureHazardAssessmentRulesService {
    @Resource
    private TcdmSecureHazardAssessmentRulesDao tcdmSecureHazardAssessmentRulesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param tsharId 主键
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardAssessmentRules queryById(Integer tsharId) {
        return this.tcdmSecureHazardAssessmentRulesDao.queryById(tsharId);
    }

    @Override
    public List<TcdmSecureHazardAssessmentRules> findList() {
        return this.tcdmSecureHazardAssessmentRulesDao.findList();
    }

    /**
     * 分页查询
     *
     * @param tcdmSecureHazardAssessmentRules 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TcdmSecureHazardAssessmentRules> queryByPage(TcdmSecureHazardAssessmentRules tcdmSecureHazardAssessmentRules, PageRequest pageRequest, Date star, Date end) {
        long total = this.tcdmSecureHazardAssessmentRulesDao.count(tcdmSecureHazardAssessmentRules);
        return new PageImpl<>(this.tcdmSecureHazardAssessmentRulesDao.queryAllByLimit(tcdmSecureHazardAssessmentRules, pageRequest,star,end), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tcdmSecureHazardAssessmentRules 实例对象
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardAssessmentRules insert(TcdmSecureHazardAssessmentRules tcdmSecureHazardAssessmentRules) {
        tcdmSecureHazardAssessmentRules.setTsharUt(new Date());
        this.tcdmSecureHazardAssessmentRulesDao.insert(tcdmSecureHazardAssessmentRules);
        return tcdmSecureHazardAssessmentRules;
    }

    /**
     * 修改数据
     *
     * @param tcdmSecureHazardAssessmentRules 实例对象
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardAssessmentRules update(TcdmSecureHazardAssessmentRules tcdmSecureHazardAssessmentRules) {
        this.tcdmSecureHazardAssessmentRulesDao.update(tcdmSecureHazardAssessmentRules);
        return this.queryById(tcdmSecureHazardAssessmentRules.getTsharId());
    }

    /**
     * 通过主键删除数据
     *
     * @param tsharId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer tsharId) {
        return this.tcdmSecureHazardAssessmentRulesDao.deleteById(tsharId) > 0;
    }

    @Override
    public List<TcdmSecureHazardAssessmentRules> queryCondition(TcdmSecureHazardAssessmentRules tcdmSecureHazardAssessmentRules) {
        return this.tcdmSecureHazardAssessmentRulesDao.queryByCondition(tcdmSecureHazardAssessmentRules);
    }
}
